#pragma once
#include<cstdlib>
#include<algorithm>
#include<string>
#include<fstream>
#include"get_editor_distance.h"
#include"list_of_constants.h"

namespace {

	long long generate_number(){
		return std::max<long long>(10,rand()*rand()*rand());
	}
	std::vector<long long> generate_sequence(){
		int cnt_words = (MOD_VALUE)+1;
		std::vector<long long> result;
		for (int i = 0; i < cnt_words; ++i)
			result.push_back(generate_number());
		return result;
	}

	std::vector<long long> generate_sequence_small(){
		int cnt_words = (MOD_VALUE2)+1;
		std::vector<long long> result;
		for (int i = 0; i < cnt_words; ++i)
			result.push_back(generate_number());
		return result;
	}

	std::vector<long long> spoil_some_numbers(const std::vector<long long>& sequence){
		std::vector<long long> result = sequence;
		for (int i = 0; i < CHANGE_VALUE; ++i)
			result[rand() % sequence.size()] = generate_number();
		return result;
	}
	std::vector<long long> spoil_some_numbers_with_delete(const std::vector<long long>& sequence){
		std::vector<long long> result = sequence;
		for (int i = 0; i < CHANGE_VALUE; ++i)
			result[rand() % sequence.size()] = generate_number();
		for (int i = 0; i < CHANGE_VALUE; ++i)
			result.erase((result.begin() + rand() % result.size()));
		for (int i = 0; i < CHANGE_VALUE; ++i)
			result.insert(result.begin() + rand() % (result.size()), generate_number());
		return result;
	}


	char generate_character(){
		return (rand() % 26) + 'a';
	}

	std::string generate_string(){
		int cnt_letters = WORD_LENGTH;
		std::string result(cnt_letters, ' ');
		for (int i = 0; i < cnt_letters; ++i)
			result[i] = generate_character();
		return result;
	}

	std::vector<std::string> spoil_some_numbers_with_delete(const std::vector<std::string>& sequence){
		std::vector<std::string> result = sequence;
		int current_value = std::max<int>(5, ((int)sequence.size()/100));
		for (int i = 0; i < current_value; ++i)
			result[rand() % sequence.size()] = generate_string();
		for (int i = 0; i < current_value; ++i)
			result.erase((result.begin() + rand() % result.size()));
		for (int i = 0; i < current_value; ++i)
			result.insert(result.begin() + rand() % (result.size()), generate_string());
		return result;
	}


	void generate_text(){
		std::ofstream writeTests1(DEFAULT_FILE1);
		int cnt_words = std::max<int>(10, generate_number() % MOD_VALUE + 1);
		std::vector<std::string> current_result;
		for (int i = 0; i < cnt_words; ++i){
			std::string generated_string = generate_string();
			current_result.push_back(generate_string());
		}

		std::vector<std::string> result2 = spoil_some_numbers_with_delete(current_result);
		for (size_t i = 0; i < current_result.size(); ++i){
			writeTests1 << current_result[i] << std::endl;
		}
		writeTests1.close();
		std::ofstream writeTests2(DEFAULT_FILE2);

		for (size_t i = 0; i < result2.size(); ++i)
			writeTests2 << result2[i] << "\n";
		writeTests2.close();
	}
}

